﻿using IcsSEMCtrl.Db;
using IcsSEMCtrl.Service.Logger;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TKT.Lifter.CIM.Lifter.Device.Service;

namespace TKT.Lifter.CIM.Lifter.Device.Unit
{
    public class Floor
    {
        //获取所有楼层信息
        private static Floor floor;
        public static Floor getFloor()
        {
            if (floor == null)
            {
                floor = new Floor();
            }
            return floor;
        }
        public Dictionary<int,FloorDao> getFloors()
        {
            Dictionary<int, FloorDao> floors = new Dictionary<int, FloorDao>();
            DBConnection dBConnection = DBControl.GetConnection();
            string sqlString = "SELECT * FROM FLOOR";
            SqlDataReader sqlDataReader = dBConnection.ExecuteQuery(sqlString);
            while (sqlDataReader.Read())
            {
                try
                {
                    FloorDao floorDao = new FloorDao();
                    floorDao.FloorID = Convert.ToInt32(sqlDataReader["FLOORID"]);
                    floorDao.FloorStartHight = sqlDataReader["FLOORSTARTHIGHT"].ToString();
                    floorDao.FloorEndHight = sqlDataReader["FLOORENDHIGHT"].ToString();
                    floorDao.FloorHight = sqlDataReader["FLOORHIGHT"].ToString();
                    floorDao.Ratio = sqlDataReader["RATIO"].ToString();
                    floors.Add(floorDao.FloorID, floorDao);
                }
                catch (Exception ex)
                {
                    LogHelper.loggerError("在getFloors方法中报错",ex);
                }
            }
            if (sqlDataReader != null)
            {
                sqlDataReader.Close();
            }
            DBControl.RemoveDBConection(dBConnection);
            return floors;
        }
    }
}
